package weixinkeji.dev.dc.buy.order.h.fwy;

import com.alibaba.fastjson.JSON;
import sys.wx.ann.hm.M;
import sys.wx.ann.power.head.SQ;
import sys.wx.c.ATR;
import sys.wx.m.db.SQL.mysql.common.orderby.OrderBy;
import sys.wx.m.db.SQL.mysql.common.where.Where;
import sys.wx.m.db.SQL.mysql.common.where.WhereConfig;
import sys.wx.m.db.dao.mysql.Dao;
import sys.wx.xy.XY;
import weixinkeji.dev.dc.DCPower;
import weixinkeji.dev.dc.base.user.bean.FWY;
import weixinkeji.dev.dc.base.user.cache.FWYConfigControl;
import weixinkeji.dev.dc.buy.order.bean.FWYOrder;
import weixinkeji.dev.dc.buy.order.so.FWYOrderSO;
import weixinkeji.dev.dc.buy.order.xy.FWYOrderXY;

@sys.wx.ann.hm.H("view/buy/order/fwy/s")

//身份类型授权。无需人工付权。
//代表 是服务员才能进行访问。
@SQ(DCPower.ID_FWY)
public class FWYKDHS {

    public static final String ORDERBY = OrderBy.getOrderBy("order_id", "DESC");

    //查询未结账的单据。
    @M("/selectMJZ")//通过 view/buy/order/fwy/s/selectMJZ.imy 访问
    public static String selectMJZ(ATR a) {
        String account = ((FWY) a.session.getAttribute(XY.SESSION_LOGIN)).getFwy_account();
        Where x = new Where(new WhereConfig(""));
        x.put(Where.TJ_IGNORE_NOTHING, "", "order_sort", "<>", FWYOrderXY.H_PAY_MONEY_ORDER);

        switch (FWYConfigControl.checkOK()) {

            case FWYConfigControl.FWY_SELECT_ALL: {
                a.printOne(JSON.toJSONStringWithDateFormat(
                        Dao.selectVastOrderBy(FWYOrder.class, x.getWhere(), ORDERBY), XY.TIME_FORMAT));
                return null;
            }
            case FWYConfigControl.FWY_SELECT_MY: {
                //查询自己的单据
                x.put(Where.TJ_IGNORE_NOTHING, Where.AND, "user_account", "=", account);
                a.printOne(JSON.toJSONStringWithDateFormat(
                        Dao.selectVastOrderBy(FWYOrder.class, x.getWhere(), ORDERBY), XY.TIME_FORMAT));
                return null;
            }
        }
        return null;
    }

    //查询指定订单的明细
    @M("/selectOne")//通过 view/buy/order/fwy/s/selectOne.imy 访问
    public static String selectOne(ATR a) {

        //取出要操作的订单表头ID
        Object order_id = a.session.getAttribute(FWYOrderXY.H_MYSELECT_ORDER);
        if (null == order_id) {
            a.out_OK_NO(false, "请先选择要操作的订单。如果还没开单，请先开单！");
            return null;
        }
        String account = ((FWY) a.session.getAttribute(XY.SESSION_LOGIN)).getFwy_account();
        a.printOne(JSON.toJSONString(FWYOrderSO.selectOneFWYOrderB_FWY(order_id.toString(), account)));
        return null;
    }
}
